import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import java.util.Date;
public class TestDate {

    public static void main(String[] args) {
        LocalDateTime currentDate =LocalDateTime.now();

        //获取当前日期所在的当周周一
        LocalDateTime firstDayOfWeek =currentDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
        //获取当前日期所在的当周周日
        LocalDateTime lastDayOfWeek =currentDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));

        System.out.println(firstDayOfWeek);
        System.out.println(lastDayOfWeek);
    }

    public static void main7(String[] args) {
        LocalDateTime dateTime =LocalDateTime.now();

        LocalDateTime newDatePlus = dateTime.plusWeeks(1);

        System.out.println("增加1周后的日期："+newDatePlus );
        LocalDateTime newDateMinus = dateTime.minusWeeks(1);
        System.out.println("减少1周后的日期："+newDateMinus );
    }

    public static void main6(String[] args) {
        LocalDateTime dateTime =LocalDateTime.now();

        LocalDateTime newDatePlus = dateTime.plusDays(1);

        System.out.println("增加1天后的日期："+newDatePlus );
        LocalDateTime newDateMinus = dateTime.minusDays(1);
        System.out.println("减少1天后的日期："+newDateMinus );
    }


    public static void main5(String[] args) {
        LocalDateTime dateTime =LocalDateTime.now();

        System.out.println("当前日期为: "+dateTime);
        //A of B  -> B 的 A
        System.out.println("本周周几: "+dateTime.getDayOfWeek().getValue());
        System.out.println("本月第几天: "+dateTime.getDayOfMonth());
        System.out.println("今年第几天: "+dateTime.getDayOfYear());
    }

    public static void main4(String[] args) {
        String stringDate = "2026-10-01 10:30:21";
        //创建一个自定义的日期时间格式化器
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        LocalDateTime date = LocalDateTime.parse(stringDate,dateTimeFormatter);
        System.out.println("当前时间为："+date );
    }

    public static void main3(String[] args) {
        LocalDateTime dateTime =LocalDateTime.now();
        System.out.println("当前时间为："+dateTime );

        int year= dateTime.getYear();
        Month month=dateTime.getMonth();
        int day= dateTime.getDayOfMonth();
        int hour= dateTime.getHour();
        int min= dateTime.getMinute();
        int sec= dateTime.getSecond();

        System.out.println("年: "+year);
        System.out.println("月: "+month.getValue());
        System.out.println("日: "+day);
        System.out.println("时: "+hour);
        System.out.println("分: "+min);
        System.out.println("秒: "+sec);

        /*LocalDate date = LocalDate.now();
        System.out.println("当前时间为："+date );
        * */
    }
    public static void main2(String[] args) {
        LocalDateTime localDateTime=LocalDateTime.now();
        System.out.println(localDateTime);

        LocalDateTime localDateTime2=LocalDateTime.of(2026,1,2,15,10,15);
        System.out.println(localDateTime2);

        //从字符串解析
        LocalDateTime parsed=LocalDateTime.parse("2023-05-15T10:30:00");
        System.out.println(parsed);
    }
    public static void main1(String[] args) {
        //1900+123
        Date date=new Date(123,0,29);
        System.out.println(date);
    }
}
